<!DOCTYPE html>
<html>

<head>
    <meta name="layout" content="main2"/>
    <g:set var="entityName" value="${message(code: 'account.label', default: 'account')}"/>
    <r:require module="export"/>
    <title>客户</title>
    <style>

    </style>
</head>

<body>
<div class="main-body">
    <div class="page-wrapper">
        <!-- Page-header start -->
        <div class="page-header">
            <div class="page-header-title">
                <h4>客户列表</h4>
            </div>

            <div class="page-header-breadcrumb">
                <ul class="breadcrumb-title">
                    <li class="breadcrumb-item">
                        <a href="/salesDashboard/index">
                            <i class="icofont icofont-home"></i>
                        </a>
                    </li>
                    <li class="breadcrumb-item"><a href="#!">客户列表</a>
                    </li>
                </ul>
            </div>
        </div>
        <!-- Page-header end -->
        <!-- Page-body start -->
        <div class="page-body">
          <g:if test="${flash.message}">
              <div class="message alert alert-info" role="status">${flash.message}
                  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                      <span aria-hidden="true">×</span></button>
              </div>
          </g:if>
            <!-- Hover table card start -->
            <div class="card">
                <div class="card-header">
                    <h5>客户列表</h5>

                    <div class="card-header-right">
                        <g:link action="create"><i class="ion-plus"></i> 新增</g:link>
                    </div>
                </div>

                <div class="card-block">

                    <div class="dt-responsive table-responsive">
                        <div id="dom-jqry_wrapper" class="dataTables_wrapper dt-bootstrap4">

                            <g:form method="POST" action="searchAccount">
                                <div class="row m-0">
                                    <div class="col-md-10 p-l-0">
                                        <div id="dom-jqry_filter" class="text-left">
                                            <label class="block">
                                                <div class="form-group row">
                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" placeholder="名称"
                                                               name="name" id="name" value="${params?.name}">
                                                    </div>

                                                    <div class="col-md-3">
                                                        <!-- <input type="text" class="form-control" placeholder="类型" name="type" id="type" value="${params?.type}"> -->
                                                        <g:select id="type" name='type' value="${params.type}"
                                                                  noSelection="${['': '类型']}" optionKey="name"
                                                                  optionValue="name"
                                                                  from="${com.next.AccountType.list()}"
                                                                  class="form-control"></g:select>
                                                    </div>

                                                    <div class="col-md-3">
                                                        <!-- <input type="text" class="form-control" placeholder="级别" name="level" id="level" value="${params?.level}"> -->
                                                        <g:select id="level" name='level' value="${params.level}"
                                                                  noSelection="${['': '级别']}" optionKey="name"
                                                                  optionValue="name"
                                                                  from="${com.next.AccountLevel.list()}"
                                                                  class="form-control"></g:select>
                                                    </div>
                                                </div>
                                            </label>
                                        </div>
                                    </div>

                                    <div class="col-md-2 p-r-0 dt-buttons">
                                        <button class="btn btn-inverse btn-sm btn-squeare" type="submit"><i
                                                class="fa fa-search"></i></button>
                                        <button class="btn btn-inverse btn-sm btn-squeare" type="button"
                                                id="resetBtn"><i class="fa fa-refresh"></i></button>
                                    </div>
                                </div>
                            </g:form>

                              <g:if test="${this.isAdmin}">
                                <g:form method="POST" action="exportAccount" id="btn-position">
                                <div class="form-group row" style="position:relative;">
                                  <div class="col-md-10">
                                    <input type="hidden" class="form-control" placeholder="名称" name="name" id="excelName" value="${params?.name}">
                                    <input type="hidden" class="form-control" placeholder="类型" name="type" id="excelType" value="${params?.type}">
                                    <input type="hidden" class="form-control" placeholder="级别" name="level" id="excelLevel" value="${params?.level}">
                                    <input type="hidden" class="form-control" placeholder="文件类型" name="f" value="excel">
                                    <input type="hidden" class="form-control" placeholder="后缀" name="extension" value="xls">
                                  </div>
                                  <div style="position:absolute; right:31px; top:-43px;">
                                    <button class="btn btn-inverse btn-sm btn-squeare" type="submit"><i class="fa fa-download"></i></button>
                                  </div>
                                </div>
                              </g:form>
                            </g:if>

                            <div class="row m-0">
                                <div class="col-xs-12 col-sm-12">
                                    <table id="dom-jqry" class="table table-striped  table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <g:sortableColumn property="id" title="编号"/>
                                            <g:sortableColumn property="name" title="名称"/>
                                            <g:sortableColumn property="user" title="所有人"/>
                                            <g:sortableColumn property="type" title="类型"/>
                                            <g:sortableColumn property="level" title="级别"/>
                                            <g:sortableColumn property="website" title="网站"/>
                                            <g:sortableColumn property="numberOfEmployees" title="雇员"/>
                                            <g:sortableColumn property="registeredCapital" title="注册资本（元）"/>
                                            <g:if test="${it?.registeredCapital >= 10000}">
                                                <g:sortableColumn property="registeredCapital" title="注册资本（万元）"/>
                                            </g:if>
                                            <g:if test="${it?.registeredCapital >= 100000000}">
                                                <g:sortableColumn property="registeredCapital" title="注册资本（亿）"/>
                                            </g:if>
                                            <g:sortableColumn property="parent" title="上级客户"/>
                                            <g:sortableColumn property="createBy" title="创建人"/>
                                            <g:sortableColumn property="modifyBy" title="修改人"/>
                                            <g:sortableColumn property="createdDate" title="创建时间"/>
                                            <g:sortableColumn property="modifiedDate" title="修改时间"/>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <g:each in="${accountList}">
                                            <tr>
                                                <td>
                                                    <g:link action="show" id="${it.id}"
                                                            class="firstTd">${it?.id}</g:link>
                                                </td>
                                                <td>
                                                    <g:link action="show" id="${it.id}"
                                                            class="firstTd">${it?.name}</g:link>
                                                </td>
                                                <td>${it?.user}</td>
                                                <td>${it?.type?.name}</td>
                                                <td>${it?.level?.name}</td>
                                                <td>${it?.website}</td>
                                                <td>${it?.numberOfEmployees}</td>
                                                <td>${Math.round(new BigDecimal(it?.registeredCapital))}</td>
                                                <td>${it?.parent}</td>
                                                <td>${it?.createBy}</td>
                                                <td>${it?.modifyBy}</td>
                                                <td>
                                                    <g:formatDate date="${it?.createdDate}"
                                                                  format="yyyy-MM-dd HH:mm:ss"></g:formatDate>
                                                </td>
                                                <td>
                                                    <g:formatDate date="${it?.modifiedDate}"
                                                                  format="yyyy-MM-dd HH:mm:ss"></g:formatDate>
                                                </td>
                                            </tr>
                                        </g:each>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            <div class="row m-0">
                                <div class="col-xs-12 col-sm-12 col-md-5">
                                    <div class="dataTables_info" id="dom-jqry_info" role="status"
                                         aria-live="polite">每页10条，共${accountCount}条</div>
                                </div>

                                <div class="col-xs-12 col-sm-12 col-md-7">
                                    <div class="dataTables_paginate" id="dom-jqry_paginate">
                                        <div class="pagination">
                                            <g:paginate total="${accountCount ?: 0}" params="${params}"/>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

            <!-- Hover table card end -->
        </div>

        <!-- Page-body end -->
    </div>
</div>
<g:javascript>

    $(function () {
        $("#resetBtn").click(function () {
            $("#name").val("");
            $("#type").val("");
            $("#select2-type-container").text("类型");
            $("#level").val("");
            $("#select2-level-container").text("级别");
        })
    });

</g:javascript>
</body>

</html>
